package com.guojizhuang.sum;

import com.guojizhuang.writable.MerchantInfoWritable;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.NullWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Job;
import org.apache.hadoop.mapreduce.lib.input.FileInputFormat;
import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;
import java.io.IOException;

public class FirstSumDriver {
    public static void main(String[] args) throws IOException, InterruptedException, ClassNotFoundException {

        //1 获取job
        Configuration conf = new Configuration();
        Job job = Job.getInstance(conf);
//        job.setInputFormatClass();

        job.setJarByClass(FirstSumDriver.class);

        job.setMapperClass(SumMapper.class);
        job.setReducerClass(sumReducer.class);

        job.setMapOutputKeyClass(Text.class);
        job.setMapOutputValueClass(LongWritable.class);

        job.setOutputKeyClass(NullWritable.class);
        job.setOutputValueClass(MerchantInfoWritable.class);

        FileInputFormat.setInputPaths(job,new Path("/user/niit/data/ijcai2016_taobao.csv"));
        FileOutputFormat.setOutputPath(job,new Path("output/guo/sum"));

        boolean result = job.waitForCompletion(true);
        System.exit(result ? 0 : 1);
    }
}
